package com.longge;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-05-08 02:36
 */
public class MinOperations {

    public int minOperations(List<Integer> nums, int k) {

        HashSet<Integer> set = new HashSet<>();
        for (int i = 1; i <= k; i++) {
            set.add(i);
        }
        for (int i = nums.size() - 1; i >= 0; i--) {
            set.remove(nums.get(i));
            if (set.isEmpty()) return nums.size() - i;
        }
        return -1;

    }

    public static void main(String[] args) {
        new MinOperations().minOperations(Arrays.asList(3,1,5,4,2),5);
    }

}
